# coding=utf-8
'''
Created on 2013-12-23

@author: sunxiang
'''
from model.user import Profile
from model.user import User
from model.user import Sites
from mongoengine import *
from datetime import datetime

import simplejson
import uuid
import hashlib


connect('test', host='localhost', port=27017)

# profile = Profile(realname='张小花',tags=['傻','女王'],avatar='http://www.gravatar.com/avatar/5cb4881acf268fd68880bf6c714a3ef4?size=48')
# sites = Sites(douban='http://www.douban.com/people/cctv-2/')
# 
# user = User(
#     uuid=uuid.uuid1(),
#     username='zhangxiaohua',
#     password=hashlib.md5('654321'.encode(encoding='utf_8', errors='strict')).hexdigest(),
#     nickname='小花', 
#     email = 'xiangmain@gmail.com',
#     profile = profile,
#     sites = sites
# )
#       
# user.save()
# print(user)


user = User.objects.filter(username = 'zhangxiaohua')
# user = User.objects.filter(uuid='61cc78d06b7e11e3b4b9005056c00001')
# print(user)
for u in user:
#     u.sites = sites
#     password = '123456'
#     u.password = hashlib.md5(password.encode(encoding='utf_8', errors='strict')).hexdigest()
#     u.save()
    u.mid = 2
#     profile = u.profile
#     profile.regtime = datetime.now()
    u.save()
    user_info = simplejson.loads(u.to_json())
    
    print(user_info)
    break